home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / lisp / eulisp / you-075a.lha / you-075a / system.c < prev    next >
C/C++ Source or Header  |  1992-06-18  |  16KB  |  786 lines

  1. /* ******************************************************************** */
  2. /* system.c          Copyright (C) Codemist and University of Bath 1989 */
  3. /*                                                                      */
  4. /* Environment specific code                                           */
  5. /* ******************************************************************** */
  6.  
  7. /*
  8.  * $Id: system.c,v 1.8 1992/06/18 19:35:29 pab Exp $
  9.  *
  10.  * $Log: system.c,v $
  11.  * Revision 1.8  1992/06/18  19:35:29  pab
  12.  * stacks grow up macro
  13.  *
  14.  * Revision 1.7  1992/06/16  19:32:16  pab
  15.  * MS-dross fixes
  16.  *
  17.  * Revision 1.6  1992/04/27  22:00:12  pab
  18.  * more volatile
  19.  *
  20.  * Revision 1.5  1992/04/26  21:09:45  pab
  21.  * added i860 support (needs checking)
  22.  *
  23.  * Revision 1.4  1992/02/10  12:01:10  pab
  24.  * Gc on/off fixes
  25.  *
  26.  * Revision 1.3  1992/01/29  13:49:07  pab
  27.  * sysV fixes
  28.  *
  29.  * Revision 1.2  1991/09/11  12:07:46  pab
  30.  * 11/9/91 First Alpha release of modified system
  31.  *
  32.  * Revision 1.1  1991/08/12  16:50:06  pab
  33.  * Initial revision
  34.  *
  35.  * Revision 1.9  1991/05/16  11:29:26  pab
  36.  * 'C' garbage collector additions
  37.  *
  38.  * Revision 1.8  1991/05/15  20:09:53  kjp
  39.  * Tidied suignal handling.
  40.  *
  41.  * Revision 1.7  1991/04/02  16:42:03  kjp
  42.  * BSD signal support.
  43.  *
  44.  * Revision 1.6  1991/02/28  13:53:54  kjp
  45.  * Fixed semaphore interaction with GC and sysv signalling.
  46.  *
  47.  * Revision 1.5  1991/02/13  18:25:46  kjp
  48.  * Pass.
  49.  *
  50.  */
  51.  
  52. #define SCHEDBUG(x) 
  53.  
  54. /*
  55.  * Change Log:
  56.  *   Version 1, April 1990
  57.  */
  58.  
  59. /*
  60.  
  61.  * This file (and it's accompanying '.h') are intended to encapsulate all
  62.  * of the system specific requirements of FEEL. For each target system
  63.  * there must be a set of functions conforming to the requested 
  64.  * configuration (e.g. if threads are required, the thread operations
  65.  * must exist along with their defined types - otherwise, they may be
  66.  * omitted).
  67.  
  68.  * It is expected that this file may degenerate into hash-includes.
  69.  
  70.  */
  71.  
  72. #include <signal.h>
  73.  
  74. #include "funcalls.h"
  75. #include "defs.h"
  76. #include "structs.h"
  77. #include "global.h"
  78. #include "error.h"
  79. #include "state.h"
  80.  
  81. #include "allocate.h"
  82. #include "garbage.h"
  83. #include "threads.h"
  84.  
  85. /*
  86.  * Nasty signal hackery! 
  87.  */
  88.  
  89. #ifdef WITH_BSD_SIGNALS
  90. #define sighold(sig) sigmask(sig)
  91. #define sigset(sig,func) signal(sig,func)
  92. #define my_sigpause(sig) sigpause(0)
  93. #else
  94. #define my_sigpause(sig) sigpause(sig)
  95. #endif
  96.  
  97. /*
  98.  * For a system to run with threads, the following must be provided:
  99.  *
  100.  *   Types: 
  101.  *     SystemSemaphore 
  102.  *
  103.  *   Functions:
  104.  *
  105.  *     char* system_malloc(int)
  106.  *     char* system_static_malloc(int)
  107.  *
  108.  *     void system_allocate_semaphore(SystemSemaphore *)
  109.  *     void system_initialise_semaphore(SystemSemaphore *)
  110.  *     void system_open_semaphore(SystemSemaphore *)
  111.  *     void system_close_semaphore(SystemSemaphore *)
  112.  *
  113.  */
  114.  
  115. SYSTEM_THREAD_SPECIFIC_DECLARATION(int,system_scheduler_number);
  116.  
  117. int system_running_processors = 1; /* Unless initialised otherwise */
  118.  
  119. /*
  120.  * Stack checking...
  121.  */
  122.  
  123. #define THREAD_STACK_MARGIN (3*1024)
  124. #define THREAD_GC_STACK_MARGIN (512)
  125.  
  126. static SYSTEM_GLOBAL(int,system_control_c_flag);
  127.  
  128. /* C-c interrupt handler... */
  129.  
  130. static void system_reenter_toplevel(LispObject *stacktop, int sig)
  131. {
  132.   IGNORE(sig);
  133.   SYSTEM_GLOBAL_VALUE(system_control_c_flag) = FALSE;
  134.   CallError(stacktop,"User Interrupt!",nil,NONCONTINUABLE);
  135. }
  136.  
  137. static void system_control_catcher(int sig)
  138. {
  139.   IGNORE(sig);
  140.   if (SYSTEM_GLOBAL_VALUE(system_control_c_flag)) {
  141.     fprintf(stderr,"Go away and leave me alone!\n");
  142.     fflush(stderr);
  143.     signal(02,system_control_catcher); /* Reinstall */
  144.     return;
  145.   }
  146.   SYSTEM_GLOBAL_VALUE(system_control_c_flag) = TRUE;
  147.   signal(02,system_control_catcher); /* Reinstall */
  148. }
  149.  
  150. int system_stacks_ok_p(LispObject *stacktop, LispObject form)
  151. {
  152.   extern LispObject interpreter_thread;
  153.   int handle;
  154.  
  155. #ifdef CHECK_KEYBOARD
  156.   {
  157.     static int eval_loops;
  158.     if (eval_loops++ == CHECK_KEYBOARD)
  159.       {  eval_loops = 0;
  160.      if (kbhit())
  161.        if (getkey() == 17)
  162.          system_control_catcher(2);
  163.        }
  164.   }
  165. #endif
  166.   if (SYSTEM_GLOBAL_VALUE(system_control_c_flag)) 
  167.     system_reenter_toplevel(stacktop,0);
  168.  
  169. #ifndef MACHINE_ANY
  170. #ifdef STACKS_GROW_UP
  171.   if ((int) &handle > STACK_BASE()+CURRENT_THREAD()->THREAD.stack_size-THREAD_STACK_MARGIN)
  172.     CallError(stacktop,"SYSTEM: C stack overflowing",form,NONCONTINUABLE);
  173. #else
  174.   if ((int) &handle - (int) (STACK_BASE()) < THREAD_STACK_MARGIN)
  175.     CallError(stacktop,"SYSTEM: C stack overflowing",form,NONCONTINUABLE);
  176. #endif
  177. #endif
  178.  
  179.   if ((CURRENT_THREAD())->THREAD.gc_stack_size 
  180.       - (int) (GC_STACK_POINTER()-GC_STACK_BASE()) * sizeof(LispObject)
  181.       < THREAD_GC_STACK_MARGIN)
  182.     {
  183.       CallError(stacktop,"SYSTEM: GC stack overflowing",form,NONCONTINUABLE);
  184.     }
  185.   return(TRUE);
  186. }
  187.  
  188. /* ******************************************************************** */
  189. /*                            Any Machine                               */
  190. /* ******************************************************************** */
  191.  
  192. #ifdef MACHINE_ANY
  193. #ifndef CGC
  194. char *system_malloc(int n)
  195. {
  196.   char *sbrk(int);
  197.   char *addr;
  198.  
  199.   if ((addr = (char *) sbrk(n)) == (char *) -1) {
  200.     perror("INITERROR: unable to allocate enough memory from system\n");
  201.     system_lisp_exit(1);
  202.   }
  203.  
  204.   return(addr);
  205. }
  206.  
  207. char *system_static_malloc(int n)
  208. {
  209.   char *sbrk(int);
  210.   char *addr;
  211.  
  212.   if ((addr = (char *) sbrk(n)) == (char *) -1) {
  213.     perror("INITERROR: out of static memory\n");
  214.     system_lisp_exit(1);
  215.   }
  216.  
  217.   return(addr);
  218. }
  219. #endif
  220. void system_lisp_exit(int n) 
  221. {
  222.   exit(n);
  223. }
  224.  
  225. void system_abort(int sig)
  226. {
  227.   fprintf(stderr,"\n\nAborting feel on signal %d\n\n",sig);
  228.   exit(sig);
  229. }
  230.  
  231. void runtime_initialise_system() 
  232. {
  233.   system_scheduler_number = 0;
  234.  
  235. #ifdef CGC
  236.   gc_init();
  237. #endif
  238.  
  239. #ifdef TRAP_ALL
  240.   signal(15,system_abort); 
  241.   signal(11,system_abort);
  242.   signal(10,system_abort);
  243.   signal(02,system_control_catcher); 
  244. #endif
  245.  
  246.   SYSTEM_INITIALISE_GLOBAL(int,system_control_c_flag,FALSE);
  247. }
  248.  
  249. #endif
  250.  
  251. /* ******************************************************************** */
  252. /*                               BSD                                    */
  253. /* ******************************************************************** */
  254.  
  255. #ifdef MACHINE_BSD
  256.  
  257. /*
  258.  * Memory allocation... 
  259.  */
  260.  
  261. char *system_malloc(int n)
  262. {
  263.   char *sbrk(int);
  264.   char *addr;
  265.  
  266.   if ((addr = (char *) sbrk(n)) == (char *) -1) {
  267.     perror("INITERROR: unable to allocate enough memory from system\n");
  268.     system_lisp_exit(1);
  269.   }
  270.  
  271.   return(addr);
  272. }
  273.  
  274. #define STATIC_MALLOC_HUNK_SIZE (4096)
  275.  
  276. char *static_free_ptr;
  277. int static_free_count;
  278.  
  279. char *system_static_malloc(int n)
  280. {
  281.   char *val;
  282.  
  283.   n = n + (n%BYTE_ALIGNMENT == 0 ? n : (BYTE_ALIGNMENT-n%BYTE_ALIGNMENT)); 
  284.   /* Alignment.. */
  285.  
  286.   if (static_free_count < n) {
  287.     char *new;
  288.  
  289.     if ((new = system_malloc(STATIC_MALLOC_HUNK_SIZE)) == NULL) {
  290.       fprintf(stderr,"INIT ERR: out of static memory\n");
  291.       exit(1);
  292.     }
  293.  
  294.     static_free_ptr = new;
  295.     static_free_count = STATIC_MALLOC_HUNK_SIZE;
  296.   }
  297.  
  298.   val = static_free_ptr;
  299.   static_free_ptr = val + n;
  300.   static_free_count -= n;
  301.  
  302.   return(val);
  303. }
  304.  
  305. /*
  306.  * Semaphores... (in header - dummies)
  307.  */
  308.  
  309. /*
  310.  * Signal handling...
  311.  */
  312.  
  313. /* Bad news signal handler... */
  314.  
  315. void system_abort(int sig)
  316. {
  317.   fprintf(stderr,"\n\nAborting EuLisp on signal %d... ",sig);
  318.   fprintf(stderr,"done\n\n");
  319.  
  320.   exit(1);
  321. }
  322.  
  323. /*
  324.  * Init and cleanup... 
  325.  */
  326.  
  327. void system_lisp_exit(int n)
  328. {
  329.   exit(n);
  330. }
  331.  
  332. void system_sleep_until_kicked() {}
  333.  
  334. void system_kick_sleepers() {}
  335.  
  336. void system_register_process(int pid) {IGNORE(pid);}
  337.  
  338. void runtime_initialise_system() 
  339. {
  340.   signal(15,system_abort); /* Catch terminations */
  341. /*
  342.   signal(11,system_abort);
  343.   signal(10,system_abort);
  344. */
  345.   signal(02,system_control_catcher); /* C-c with any luck */
  346.  
  347.   system_scheduler_number = 0;
  348. #ifdef CGC
  349.    gc_init();
  350. #endif
  351.  
  352.  
  353.   SYSTEM_INITIALISE_GLOBAL(int,system_control_c_flag,FALSE);
  354. }
  355.  
  356. #endif
  357.  
  358. /* ******************************************************************** */
  359. /*                             System V                                 */
  360. /* ******************************************************************** */
  361.  
  362. #ifdef MACHINE_SYSTEMV
  363.  
  364. /*
  365.  * Memory allocation...
  366.  */
  367.  
  368. /* Of shared memory segments... */
  369.  
  370. #define MAX_SHARED_SEGMENTS 100
  371.  
  372. int shared_ids[MAX_SHARED_SEGMENTS];
  373. int shared_segment_count;
  374.  
  375. #if i860
  376. #include <errno.h>
  377. #define MAX_SHARED_PAGE_SZ 1024*1024
  378. #define PAGE_BOUNDARY 4096
  379.   char *system_malloc(int n)
  380.   {
  381.  char *alloc_memory_block(int size);
  382.  char *addr=0;
  383.  int k=0;
  384.  int left=n;
  385.  
  386.  if (n==0)
  387.    return NULL;
  388.  
  389.  while (left > MAX_SHARED_PAGE_SZ || addr==0)
  390.    {
  391.      if (addr==0)
  392.     addr=alloc_memory_block(MAX_SHARED_PAGE_SZ);
  393.      else 
  394.     alloc_memory_block(MAX_SHARED_PAGE_SZ);
  395.      left -=MAX_SHARED_PAGE_SZ;
  396.    }
  397.  if (left>0)
  398.    alloc_memory_block(left);
  399.  return addr;
  400. }
  401.  
  402. char *alloc_memory_block(int size)
  403. {
  404.  static int id=0;
  405.  char *addr;
  406.  int res;
  407.  
  408.  if (id==0)
  409.    id=25;
  410.  printf("alloc: %d %d\n",id,size);
  411.  
  412.  if (size==0)
  413.    return NULL;
  414.  
  415.  if ((size&(PAGE_BOUNDARY-1)))
  416.    size=(size+PAGE_BOUNDARY)&(~(PAGE_BOUNDARY-1));
  417.  
  418.  addr=sbrk(0);
  419.  if (((int)addr&(PAGE_BOUNDARY-1)))
  420.    addr= (char *)(((int)addr+PAGE_BOUNDARY)&(~(PAGE_BOUNDARY-1)));
  421.  
  422.  if (brk(addr+size)==-1)
  423.    perror("Brk");
  424.  printf("allocating: %x,%x\n",addr,size);
  425.  do
  426.    {
  427.      extern volatile int errno;
  428.      errno=0;
  429.      id++;
  430.      res=create_shared_region(id,addr,size,0);
  431.      if (res<0)
  432.     perror("create");
  433.    }
  434.  while (res==-1 && errno==EINVAL);
  435.  
  436.  if (res== -1)
  437.    perror("create");
  438.  shared_ids[shared_segment_count] = id;
  439.  
  440.  ++shared_segment_count;  
  441.  id++;
  442.  
  443.  return addr;
  444. }
  445.  
  446.  
  447. #else
  448. char *system_malloc(int n)
  449. {
  450.   int seg;
  451.   char *addr;
  452.  
  453.   if (shared_segment_count >= MAX_SHARED_SEGMENTS) {
  454.     fprintf(stderr,"Can't allocate shared segment\n");
  455.     system_lisp_exit(1);
  456.   }
  457.  
  458.   if ((seg = shmget(IPC_PRIVATE,n,511|IPC_CREAT)) < 0) {
  459.     perror("shmget\n");
  460.     system_lisp_exit(1);
  461.   }
  462.  
  463.   if ((int) (addr = shmat(seg,NULL,NULL)) == -1) {
  464.     perror("shmat\n");
  465.     system_lisp_exit(1);
  466.   }
  467.  
  468.   shared_ids[shared_segment_count] = seg;
  469.  
  470.   ++shared_segment_count;
  471.  
  472.   return(addr);
  473. }
  474. #endif
  475. /* Of static shared bits (assumes serial for now)... */
  476.  
  477. #define STATIC_MALLOC_HUNK_SIZE (4096)
  478.  
  479. char *static_free_ptr;
  480. int static_free_count;
  481.  
  482. char *system_static_malloc(int n)
  483. {
  484.   char *val;
  485.  
  486.   n = n + (n%BYTE_ALIGNMENT == 0 ? n : (BYTE_ALIGNMENT-n%BYTE_ALIGNMENT)); 
  487.   /* Alignment.. */
  488.  
  489.   if (static_free_count < n) {
  490.     char *new;
  491.  
  492.     if ((new = system_malloc(STATIC_MALLOC_HUNK_SIZE)) == NULL) {
  493.       fprintf(stderr,"INIT ERR: out of static memory\n");
  494.       system_lisp_exit(1);
  495.     }
  496.  
  497.     static_free_ptr = new;
  498.     static_free_count = STATIC_MALLOC_HUNK_SIZE;
  499.   }
  500.  
  501.   val = static_free_ptr;
  502.   static_free_ptr = val + n;
  503.   static_free_count -= n;
  504.  
  505.   return(val);
  506. }
  507.  
  508. /*
  509.  * Semaphores...
  510.  */
  511.  
  512. void system_initialise_semaphore(SystemSemaphore *ptr)
  513. {
  514.   *ptr = 1;
  515. }
  516.  
  517. void system_allocate_semaphore(SystemSemaphore *ptr)
  518. {
  519.   *ptr = 1;
  520. }
  521. /* SystemV Semaphores excluded */
  522.  
  523. #ifdef SEMAPHORES_SOFTWARE
  524.  
  525. #include "lamport.h"
  526.  
  527. LamportSemaphore system_semaphore;
  528.  
  529. void system_open_semaphore(LispObject *stacktop, SystemSemaphore *ptr)
  530. {
  531.   extern SYSTEM_GLOBAL(SystemSemaphore,GC_sem);
  532.   int mine_flag = FALSE;
  533.  
  534.  top:
  535.  
  536.   lamport_enter(system_semaphore,system_scheduler_number);
  537.  
  538.   if (*ptr == 1) {
  539.     *ptr = 0;
  540.     mine_flag = TRUE;
  541.   }
  542.  
  543.   lamport_exit(system_semaphore,system_scheduler_number);
  544.  
  545.   if (mine_flag) return;
  546.  
  547.   if (ptr != &SYSTEM_GLOBAL_VALUE(GC_sem))
  548.     while (*(volatile SystemSemaphore *)ptr != 1) GC_sync_test();
  549.   else
  550.     while (*(volatile SystemSemaphore *)ptr != 1);
  551.  
  552.   goto top;
  553. }
  554.  
  555. int system_maybe_open_semaphore(LispObject *stacktop, SystemSemaphore *ptr)
  556. {
  557.   int mine_flag = FALSE;
  558.  
  559.   lamport_enter(system_semaphore,system_scheduler_number);
  560.  
  561.   if (*ptr == 1) {
  562.     *ptr = 0;
  563.     mine_flag = TRUE;
  564.   }
  565.  
  566.   lamport_exit(system_semaphore,system_scheduler_number);
  567.  
  568.   GC_sync_test();
  569.  
  570.   return(mine_flag);
  571. }
  572.  
  573. #endif
  574.  
  575. void system_close_semaphore(SystemSemaphore *ptr)
  576. {
  577.   *ptr = 1;
  578. }
  579.  
  580. /*
  581.  * Signal handling...
  582.  */
  583.  
  584. static SYSTEM_GLOBAL_ARRAY1(int,system_pids,MAX_PROCESSORS);
  585.  
  586. /* Bad news, free up semaphores and shared memory... */
  587.  
  588. void system_abort(int sig)
  589. {
  590.   int i;
  591.  
  592.   fprintf(stderr,"\n\nAborting EuLisp on signal %d... ",sig);
  593.  
  594.   for (i=0;i<shared_segment_count;++i) {
  595.     (void) shmctl(shared_ids[i],IPC_RMID,NULL);
  596.   }
  597.  
  598.  
  599. #if i860
  600.   for (i=0; i<shared_segment_count ; i++)
  601.     delete_shared_region(shared_ids[i]);
  602. #else
  603.     for (i=0;i<shared_segment_count;++i) {
  604.       (void) shmctl(shared_ids[i],IPC_RMID,NULL);
  605.     }
  606. #endif
  607.   /* Kill of other processes too */
  608.  
  609.   for (i=0; i<RUNNING_PROCESSORS(); ++i)
  610.     if (i != system_scheduler_number)
  611.       kill(SYSTEM_GLOBAL_ARRAY1_VALUE(system_pids,i),SIGQUIT);
  612.  
  613.   fprintf(stderr,"done\n\n");
  614.  
  615.   exit(1);
  616. }
  617.  
  618. /*
  619.  * Init and cleanup... 
  620.  */
  621.  
  622. void system_lisp_exit(int n)
  623. {
  624.   int i;
  625.  
  626.   for (i=0;i<shared_segment_count;++i) {
  627.     (void) shmctl(shared_ids[i],IPC_RMID,NULL);
  628.   }
  629.  
  630.   (void) semctl(system_semaphore,NULL,IPC_RMID,NULL);
  631.  
  632.   /* Kill of other processes too */
  633.  
  634.   for (i=0; i<RUNNING_PROCESSORS(); ++i)
  635.     if (i != system_scheduler_number)
  636.       kill(SYSTEM_GLOBAL_ARRAY1_VALUE(system_pids,i),SIGQUIT);
  637.  
  638.   exit(n);
  639. }
  640.  
  641. /*
  642.  * Signal fiddling...
  643.  */
  644.  
  645. #define KICK_SIGNAL (SIGUSR1)
  646.  
  647. void system_kick_pid(int pid)
  648. {
  649.   extern int kill(int,int);
  650.  
  651.   (void) kill(pid,KICK_SIGNAL);
  652. }
  653.  
  654. static void system_nout()
  655. {
  656.   sigset(KICK_SIGNAL,system_nout);
  657. }
  658.  
  659. void system_sleep_until_kicked()
  660. {
  661.   extern int sigpause(int);
  662.  
  663.   (void) my_sigpause(KICK_SIGNAL);
  664.   sighold(KICK_SIGNAL);
  665. /*
  666.   fprintf(stderr,"{W:%d}\n",system_scheduler_number); fflush(stderr);
  667. */
  668.   fflush(stderr);
  669. }
  670.  
  671. static void system_read_nout()
  672. {
  673.   sigset(KICK_SIGNAL,system_read_nout);
  674. /*  GC_sync_test();*/
  675. }
  676.  
  677. #include <errno.h>
  678.  
  679. int system_read(int fno,char *buf,int max)
  680. {
  681.   int error;
  682.  
  683.   (void) sigset(KICK_SIGNAL,system_read_nout);
  684.  
  685.   do {
  686.  
  687.     error = read(fno,buf,max);
  688.     if (error > 0) {
  689.  
  690.       sigset(KICK_SIGNAL,system_nout);
  691.       (void) sighold(KICK_SIGNAL);
  692.  
  693. #ifndef i860
  694.       PROFILE(printf("PVAL:%x\n",PROFILE_TIME(system_local_timer)));
  695. #endif
  696.       fflush(stdout);
  697.       return(error);
  698.     }
  699.  
  700.   } while (errno == EINTR);
  701.  
  702.   return(error);
  703. }
  704.  
  705. void system_kick_sleepers()
  706. {
  707.   int i;
  708.  
  709.   for (i=0; i<RUNNING_PROCESSORS(); ++i)
  710.     if (i != system_scheduler_number)
  711.       kill(SYSTEM_GLOBAL_ARRAY1_VALUE(system_pids,i),KICK_SIGNAL);
  712. }
  713.  
  714. #ifndef i860
  715. DEF_PROFILE_TIMER(system_local_timer);
  716. #endif
  717.  
  718. void system_register_process(int n)
  719. {
  720.   SYSTEM_GLOBAL_ARRAY1_VALUE(system_pids,n) = getpid();
  721.   sigset(KICK_SIGNAL,system_nout);
  722.   sighold(KICK_SIGNAL);
  723.  
  724. #ifdef i860
  725.   INIT_PROFILE_TIMER(system_local_timer);
  726. #endif
  727. }
  728.  
  729. void runtime_initialise_system()
  730. {
  731.  
  732. #ifdef SEMAPHORES_SYSTEMV
  733.  
  734.   if ((system_semaphore = semget(IPC_PRIVATE,1,511)) < 0) {
  735.     perror("INIT ERROR: can't get semaphore\n");
  736.     exit(1);
  737.   }
  738.   if (semctl(system_semaphore,0,SETVAL,1) < 0) {
  739.     perror("INIT ERROR: initialise semaphore\n");
  740.     exit(1);
  741.   }
  742.  
  743.   system_sem_handler_array[0][0].sem_num = 0;
  744.   system_sem_handler_array[0][0].sem_op = -1;
  745.   system_sem_handler_array[0][0].sem_flg = NULL;
  746.  
  747. #endif
  748.  
  749.   shared_segment_count = 0;
  750.  
  751.   static_free_ptr = NULL;
  752.   static_free_count = 0;
  753.  
  754.   /* Bad news signals */
  755.  
  756.   sigset(SIGTERM,system_abort); /* Catch terminations */
  757.   sigset(SIGQUIT,system_abort); /* Quits */
  758.   sigset(SIGSEGV,system_abort); /* Segmentation faults */
  759.   sigset(SIGBUS,system_abort);  /* Bus errors */
  760.  
  761.   /* Error trapped signals */
  762.  
  763.   sigset(SIGINT,system_control_catcher); /* C-c with any luck */
  764.  
  765.   /* Ignore kick signals until we need them */
  766.  
  767.   sighold(KICK_SIGNAL); 
  768.  
  769. #ifdef SEMAPHORES_SOFTWARE
  770.  
  771.   system_semaphore 
  772.     = (LamportSemaphore) 
  773.         system_static_malloc(sizeof(struct lamport_semaphore));
  774.   lamport_initialise(system_semaphore);
  775.  
  776.   SYSTEM_INITIALISE_GLOBAL_ARRAY1(int,system_pids,MAX_PROCESSORS,0);
  777.   SYSTEM_GLOBAL_ARRAY1_VALUE(system_pids,0) = getpid();
  778.  
  779. #endif
  780.  
  781.   SYSTEM_INITIALISE_GLOBAL(int,system_control_c_flag,FALSE);
  782. }
  783.  
  784. #endif
  785.  
  786.